package com.models
{
	import com.AppConfing;
	import com.messagers.AppLoadUIMessager;
	import com.vo.ButtonVO;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;
	
	import starling.utils.AssetManager;
	/**
	 *  
	 * @author shishujun
	 * 
	 */	
	public class UIBaseProxy extends Proxy implements IProxy
	{
		public static const NAME : String = "UIBaseProxy";
		private var buttonobj : Object;
		
		public function UIBaseProxy()
		{
			super(NAME);
		}
		
		/**
		 * 加载通用的基本界面资源
		 * 
		 */		
		public function loadbaseUIAssets() : void
		{
			AppLoadUIMessager.loadbaseUIAssets(loadComplete);
		}
		
		private function loadComplete(baseUIAssetManager : AssetManager) : void
		{
			trace("加载基本通用资源成功……");
			disposeAssets(baseUIAssetManager);
			sendNotification(AppConfing.BASEUI_LOADCOMPLETE);
		}
		
		private function disposeAssets(baseUIAssetManager : AssetManager) : void
		{
			//获取通用所以按钮的纹理集
			buttonobj = new  Object;
			var btnnamelist : Vector.<String> = baseUIAssetManager.getTextureNames("basebtn_");
			var btnlength : int = btnnamelist.length;
			var i : int;
			var texturename : String;
			var key : String;
			var strlist : Array;
			var texturekey : String;
			for(i = 0; i < btnlength; ++i)
			{
				texturename = btnnamelist[i];
				strlist = texturename.split("_");
				key = strlist[1];
				if(buttonobj[key] == null)
				{
					buttonobj[key] = new ButtonVO();
					buttonobj[key]["type"] = 0;
				}
				buttonobj[key].buttonName = key;
				texturekey = strlist[2]+"Texture";
				buttonobj[key][texturekey] = baseUIAssetManager.getTexture(texturename);
				
			}
			AppConfing.baseBtnKey = key;
			
			//获取通用所以图片的纹理集
			var imgnamelist : Vector.<String> = baseUIAssetManager.getTextureNames("baseimg_");
		}
		
		/**
		 * 获取基础组件中button的所有资源集合 
		 * @return 
		 * 
		 */		
		public function get buttonObj() : Object
		{
			return buttonobj;
		}
	}
}